package com.ruoyi.project.dict.cizu.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.cizu.domain.CizuDetail;
import com.ruoyi.project.dict.cizu.service.ICizuDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 词组详情Controller
 * 
 * @author shixiangwen
 * @date 2020-01-15
 */
@Controller
@RequestMapping("/dict/cizu")
public class CizuDetailController extends BaseController
{
    private String prefix = "dict/cizu";

    @Autowired
    private ICizuDetailService cizuDetailService;

    @RequiresPermissions("dict:cizu:view")
    @GetMapping()
    public String cizu()
    {
        return prefix + "/cizu";
    }

    /**
     * 查询词组详情列表
     */
    @RequiresPermissions("dict:cizu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CizuDetail cizuDetail)
    {
        startPage();
        List<CizuDetail> list = cizuDetailService.selectCizuDetailList(cizuDetail);
        return getDataTable(list);
    }

    /**
     * 导出词组详情列表
     */
    @RequiresPermissions("dict:cizu:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CizuDetail cizuDetail)
    {
        List<CizuDetail> list = cizuDetailService.selectCizuDetailList(cizuDetail);
        ExcelUtil<CizuDetail> util = new ExcelUtil<CizuDetail>(CizuDetail.class);
        return util.exportExcel(list, "cizu");
    }

    /**
     * 新增词组详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存词组详情
     */
    @RequiresPermissions("dict:cizu:add")
    @Log(title = "词组详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CizuDetail cizuDetail)
    {
        return toAjax(cizuDetailService.insertCizuDetail(cizuDetail));
    }

    /**
     * 修改词组详情
     */
    @GetMapping("/edit/{w}")
    public String edit(@PathVariable("w") String w, ModelMap mmap)
    {
        CizuDetail cizuDetail = cizuDetailService.selectCizuDetailById(w);
        mmap.put("cizuDetail", cizuDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存词组详情
     */
    @RequiresPermissions("dict:cizu:edit")
    @Log(title = "词组详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CizuDetail cizuDetail)
    {
        return toAjax(cizuDetailService.updateCizuDetail(cizuDetail));
    }

    /**
     * 删除词组详情
     */
    @RequiresPermissions("dict:cizu:remove")
    @Log(title = "词组详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cizuDetailService.deleteCizuDetailByIds(ids));
    }
}
